/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: BaseController
 * Author:   zhouheng
 * Date:     2018/6/19 13:04
 * Description: 基类控制器
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.modular.base.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hengby.hengcrud.core.page.PageInfoBT;
import com.hengby.hengcrud.core.support.HttpKit;
import com.hengby.hengcrud.modular.base.tips.SuccessTips;
import com.hengby.hengcrud.modular.base.wrap.BaseControllerWarpper;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈基类控制器〉
 *
 * @author zhouheng
 * @create 2018/6/19
 * @since 1.0.0
 */
public class BaseController {
    public static String SUCCESS = "SUCCESS";
    public static String ERROR = "ERROR";

    public static String REDIRECT = "redirect:";
    public static String FORWARD = "forward:";

    public static SuccessTips SUCCESS_TIP = new SuccessTips();

    protected HttpServletRequest getHttpServletRequest() {
        return HttpKit.getRequest();
    }

    protected HttpServletResponse getHttpServletResponse() {
        return HttpKit.getResponse();
    }

    protected HttpSession getSession() {
        return HttpKit.getRequest().getSession();
    }

    protected HttpSession getSession(Boolean flag) {
        return HttpKit.getRequest().getSession(flag);
    }

    protected String getPara(String name) {
        return HttpKit.getRequest().getParameter(name);
    }

    protected void setAttr(String name, Object value) {
        HttpKit.getRequest().setAttribute(name, value);
    }

    /**
     * 把service层的分页信息，封装为bootstrap table通用的分页封装
     */
    protected <T> PageInfoBT<T> packForBT(Page<T> page) {
        return new PageInfoBT<T>(page);
    }

    /**
     * 包装一个list，让list增加额外属性
     */
    protected Object warpObject(BaseControllerWarpper warpper) {
        return warpper.wrap();
    }

    /*protected Map<String, Object> getDataTable(PageInfo<?> pageInfo) {
        Map<String, Object> rspData = new HashMap<>();
        rspData.put("rows", pageInfo.getList());
        rspData.put("total", pageInfo.getTotal());
        return rspData;
    }*/


}